package com.example.recyclerviewfenzu.JAC;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.recyclerviewfenzu.R;

import java.util.List;

/**
 * @功能:
 * @Creat 2020/3/14 15:08
 * @User Lmy
 * @Compony JinAnChang
 */
public class RecyclerViewAdapter1 extends RecyclerView.Adapter<RecyclerViewAdapter1.ViewHolder> implements RecyclerViewAdapter2.OnItemClickListener {
    private Context context;
    private List<DataListBean.DataBean> dataListBean;
    private RecyclerViewAdapter2 adapter2;

    private ViewHolder holders;

    public RecyclerViewAdapter1(Context context, List<DataListBean.DataBean> dataListBean) {
        this.context = context;
        this.dataListBean = dataListBean;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyclerview1_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holders = holder;
        holder.tvTitle.setText(dataListBean.get(position).getTitle());
        adapter2 = new RecyclerViewAdapter2(context, dataListBean.get(position).getStateList());
        adapter2.setOnItemClickListener(this);
        holder.reclclerview2.setNestedScrollingEnabled(false);//禁止滑动
        holder.reclclerview2.setLayoutManager(new LinearLayoutManager(context));
        holder.reclclerview2.setAdapter(adapter2);
    }

    @Override
    public int getItemCount() {
        return dataListBean.size();
    }

    @Override
    public void TimeClickListener(int position) {
        //这里由于数据源并没有改变所有全部刷新 也不会改变当前选中的view的位置  不刷=新最外层的列表 而是第二层列表的话 会导致刷新之后当前位置的变化
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitle;
        private RecyclerView reclclerview2;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            tvTitle = itemView.findViewById(R.id.tv_title);
            reclclerview2 = itemView.findViewById(R.id.reclclerview2);
        }
    }
}
